#include "BookView.h"

BookView::BookView()
{
     option = 0;
     title = "";
     author = "";
     isbn = "";
     editor = "";
     category = "";    
     book = null; 
     books = new LinkedList<Book>();   
}

Book* BookView::createBook()
{
      print = utilities->getInput("Introducing of Books\n");
      title = utilities->getInput("Enter the Title: "); 
      author = utilities->getInput("Enter the Author: ");
      isbn = utilities->getInput("Enter the Isbn: ");
      editor = utilities->getInput("Enter the Publisher: ");
      category = utilities->getInput("Enter the Category: ");
      book = new Book(title,author, isbn, editor, category);
      return book;     
}

void BookView::add()
{
    book = createBook(); 
    books->add(book);
}

void BookView::edit()
{
     showBooks();
     option = utilities->getInt("Choose Which Modify: ");
     option--;
     book = createBook(); 
     books->edit(book,option);
}

void BookView::remove()
{
     showBooks();
     option = utilities->getInt("Choose Which Delete: ");
     option--;
     books->remove(option);        
}

void BookView::showBooks(){

Node<Book>* i = books->getFirst();
int x = 1;

while(i != NULL){

        cout << "Book No." << x++ << "\n";
        cout << "Title: " << i->getData()->getTitle() <<"\n"; 
        cout << "Author: " << i->getData()->getAuthor() << "\n";
        cout << "ISBN: " << i->getData()->getIsbn() << "\n";
        cout << "Publisher: " << i->getData()->getEditor() << "\n";
        cout << "Category: " << i->getData()->getCategory() << "\n\n";
        i = i->getNext();        
  }      
}

void BookView::show(){

 utilities->clearScreen(); 
 utilities->printText(" Maintenances of Books\n");
 utilities->printText("1. Add Books: \n");
 utilities->printText("2. Modify Books: \n");
 utilities->printText("3. Delete Books: \n");
 utilities->printText("4. Back: \n");
 option = utilities->getInt("Choose The Option: ");
 
 switch(option){
                
 case 1:
  utilities->clearScreen();   
  add(); 
  show(); 
  break;

 case 2: 
  utilities->clearScreen(); 
  edit(); 
  show();
  break;
  
 case 3: 
  utilities->clearScreen();
  remove();
  show(); 
  break;
  } 

}
